#include<stdio.h>
#include<stdlib.h>
#include<signal.h>

void handler(int sig)
{
	
	int status=0;
	while(waitpid(-1,&status,WNOHANG)>0)
	{
		printf("code signal%d,code exit %d\n",status&0xff,(status>>8)&0xff);
	}
}

int main()
{
	pid_t id;
	id=fork();
	if(id<0){
	}else if(id==0){//child
		sleep(10);
		printf("child will return...\n");
		exit(1);
	}else{
		signal(SIGCHLD,handler);
		int i=2;
		while(i++){
				sleep(1);
				if(i%5==0)
			 	{
			    	pid_t id;
			    	id=fork();
			    	if(id==0)
			    	{
			    			sleep(5);exit(i);
			    	}
			 	}
				printf("do anything..\n");
		}
	}
}
